package com.ali.resource.ControllerPage;

import com.ali.resource.CompoentPage.EcsComponent;
import com.ali.resource.MapPage.ecs.EcsMap;
import com.ali.resource.ServicePage.EcsService;
import com.ali.resource.ShareTools.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.tags.Tags;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.naming.Name;
import java.util.ArrayList;
import java.util.List;

@Tag(name = "ecs接口文档" , description = "ecs资源信息查询")
@RestController
@RequestMapping("/ecs")
public class EcsController {


    @Autowired
    private EcsComponent ecsComponent;

    @Autowired
    private EcsService ecsService;


    @Operation(summary = "getList",description = "获取ecs列表")
    @Parameter(name = "bool", description = "是否下载至xlsx")
    @GetMapping("/getList")
    public Result getList(@RequestParam(required = true,defaultValue = "false") String bool
                        , @RequestParam(required = false) String instanceIdPrefix
                        , @RequestParam(required = false) String instanceNamePrefix
                        ) throws Exception {
        ArrayList<EcsMap> list = ecsService.getList(bool,instanceIdPrefix,instanceNamePrefix);

        if (bool.equals("true")){
            ecsService.getExecl(list);
        }


        return Result.builder().code(200).total(list.size()).data(list).build();
    }


}
